package com.example.myapplication.model;

import com.example.mvp.model.BaseModel;
import com.example.myapplication.Bean.Demo;
import com.example.myapplication.Callback.HttpCallBack;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.trello.rxlifecycle2.LifecycleProvider;

import java.util.List;

import mylibrary.client.HttpClient;

public class MainModel implements BaseModel {
    public void getData(MainCallBack mainCallBack, LifecycleProvider lifecycleProvider){
        new HttpClient.Buidler()
                .setApiUrl("article/listproject/0/json")
                .setBaseUrl("https://wanandroid.com/")
                .setLifecycleProvider(lifecycleProvider)
                .get()
                .build()
                .excute(new HttpCallBack<List<Demo.DatasBean>>() {

                    @Override
                    protected void error(String error, int code) {

                    }

                    @Override
                    protected void onSucess(List<Demo.DatasBean> datasBeans) {
                        mainCallBack.showList(datasBeans);
                    }

                    @Override
                    public List<Demo.DatasBean> convert(JsonElement jsonElement) {
                        Demo demo = new Gson().fromJson(jsonElement, Demo.class);
                        return demo.getDatas();
                    }
                });
    }

    public interface MainCallBack{
        void showList(List<Demo.DatasBean> datasBeans);
        void showError(String error,int code);
    }


    }






